<!--
@license
Copyright 2024 The Model Explorer Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================
-->

<div class="container"
    [bubble]="help"
    [overlaySize]="helpPopupSize"
    [hoverDelayMs]="10"
    [class.enabled]="syncEnabled()">
  <div class="content"
      [bubbleClick]="dropdown"
      [overlaySize]="dropdownSize">
    <mat-icon [class.loading]="loadingFromCns()">
      {{syncIcon()}}
    </mat-icon>
    <div>Sync</div>
  </div>
</div>

<ng-template #help>
  <div class="model-explorer-help-popup">
    Synchronize the node selection across two panes by the given node id mapping.
  </div>
</ng-template>

<ng-template #dropdown>
  <div class="model-explorer-sync-navigation-dropdown">
    <div class="section-label">
      <div>Select a sync mode</div>
      <div class="right">
        <a href="https://github.com/google-ai-edge/model-explorer/wiki/2.-User-Guide#synchronize-navigation"
          target="_blank">
          Guide
        </a>
        <div class="icon-container" bubbleClose>
          <mat-icon class="close">close</mat-icon>
        </div>
      </div>
    </div>
    @for (mode of allSyncModes; track mode) {
      <div class="section">
        <div class="select-container">
          <label class="sync-mode-radio-button">
            <input type="radio" name="mode"
                [checked]="syncMode() === mode"
                [class.cns]="mode === SyncNavigationMode.LOAD_MAPPING_FROM_CNS"
                (change)="setSyncMode(mode)" />
            {{getModeLabel(mode)}}
          </label>
          @switch (mode) {
            @case (SyncNavigationMode.MATCH_NODE_ID) {
              <label class="match-node-id-checkbox">
                <input type="checkbox"
                    name="match-node-id-checkbox"
                    [checked]="matchNodeIdHighlightDiffs()"
                    [disabled]="syncMode() !== SyncNavigationMode.MATCH_NODE_ID"
                    #input
                    (change)="handleToggleMatchNodeIdHighlightDiffs(input.checked)"/>
                Highlight deleted and new nodes
              </label>
            }
            @case (SyncNavigationMode.UPLOAD_MAPPING_FROM_COMPUTER) {
              <button class="upload-mapping-button"
                  mat-flat-button color="primary"
                  (click)="handleClickUpload(input)">
                Upload
              </button>
              <input class="upload-mapping-input"
                  type="file" #input
                  accept=".json"
                  (change)="handleUploadedFileChanged(input)">
              <div class="uploaded-file-name">
                {{uploadedFileName}}
              </div>
            }
          }
        </div>
      </div>
    }
  </div>
</ng-template>